//
//  MGAlertBottomViewController.m
//  Express
//
//  Created by lhongl on 2025/9/25.
//  Copyright © 2025 QM. All rights reserved.
//

#import "MGAlertBottomViewController.h"
#import "MGPresentationController.h"
@interface MGAlertBottomViewController () <UIViewControllerTransitioningDelegate>

///
@property (nonatomic, assign) CGRect frame;

@end

@implementation MGAlertBottomViewController

- (instancetype)init{
    if(self = [super init]){
        self.modalPresentationStyle = UIModalPresentationCustom;
        self.isActionBackgroundDismiss = NO;
        self.contentSize = CGSizeMake(self.view.frame.size.width, 300);
        self.transitioningDelegate = self;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    double cornerRadius = 16;
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.view.bounds byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(cornerRadius, cornerRadius)];
    CAShapeLayer *layer = [[CAShapeLayer alloc] init];
     layer.frame = self.view.bounds;
    layer.path = path.CGPath;
    self.view.layer.mask = layer;
    // Do any additional setup after loading the view.
}

- (CGSize)contentSize{
    return CGSizeMake(self.view.frame.size.width, 300);
}

- (BOOL)isActionBackgroundDismiss {
    return YES;
}


#pragma mark delegate-弹出视图代理

// 返回控制控制器弹出动画的对象
/**
 presentedViewController     将要跳转到的目标控制器
 presentingViewController    跳转前的原控制器
 */
- (UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source{
    CGFloat windowH = [UIScreen mainScreen].bounds.size.height;
    CGFloat windowW = [UIScreen mainScreen].bounds.size.width;
    CGSize size = [self contentSize];
    CGRect frame = CGRectMake((windowW - size.width)/2, windowH - size.height, size.width, size.height);
    MGPresentationController *presentVC = [[MGPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting frame:frame];
    presentVC.isActionBackgroundDismiss = [self isActionBackgroundDismiss];
    return presentVC;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
